import Vue from 'vue'
import Vuex from 'vuex'
import {getItem,setItem} from '@/utils/storage'

Vue.use(Vuex)
const TOKEN_KEY = 'TOUTIAO_USER'

export default new Vuex.Store({
  state: {
    // 用来存储当前用户信息
    // user:null
    // user: JSON.parse(window.localStorage.getItem(TOKEN_KEY))
    user:getItem(TOKEN_KEY)
  },
  mutations: {
    setUser (state,data) {
    state.user = data

    //为了防止丢失我们需要把数据备份到本地存储
    // window.localStorage.setItem(TOKEN_KEY,JSON.stringify(state.user))
    setItem(TOKEN_KEY,state.user)
  }
  },
  actions: {
  },
  modules: {
  }
})
